package com.apex.shared.mybatis.handler;

import com.apex.shared.mybatis.config.TenantContextHolder;
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
import jakarta.annotation.Resource;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.schema.Column;

import java.util.List;

/**
 * Apex CustomTenantHandler
 *
 * @author Bangda Xiao
 */
//@Component
public class CustomTenantHandler implements TenantLineHandler {

    @Resource
    TenantContextHolder tenantContextHolder;

    @Override
    public Expression getTenantId() {
        String tenantId = tenantContextHolder.getCurrentTenantId();
        return new StringValue(tenantId);
    }

    @Override
    public String getTenantIdColumn() {
        return TenantLineHandler.super.getTenantIdColumn();
    }

    @Override
    public boolean ignoreTable(String tableName) {
        return TenantLineHandler.super.ignoreTable(tableName);
    }

    @Override
    public boolean ignoreInsert(List<Column> columns, String tenantIdColumn) {
        return TenantLineHandler.super.ignoreInsert(columns, tenantIdColumn);
    }
}
